{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Reverse String II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #two-pointers #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #双指针 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: reverseStr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #反转字符串 II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给定一个字符串 <code>s</code> 和一个整数 <code>k</code>，从字符串开头算起，每计数至 <code>2k</code> 个字符，就反转这 <code>2k</code> 字符中的前 <code>k</code> 个字符。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>如果剩余字符少于 <code>k</code> 个，则将剩余字符全部反转。</li>\n",
    "\t<li>如果剩余字符小于 <code>2k</code> 但大于或等于 <code>k</code> 个，则反转前 <code>k</code> 个字符，其余字符保持原样。</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"abcdefg\", k = 2\n",
    "<strong>输出：</strong>\"bacdfeg\"\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"abcd\", k = 2\n",
    "<strong>输出：</strong>\"bacd\"\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>\n",
    "\t<li><code>s</code> 仅由小写英文组成</li>\n",
    "\t<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [reverse-string-ii](https://leetcode.cn/problems/reverse-string-ii/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [reverse-string-ii](https://leetcode.cn/problems/reverse-string-ii/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abcdefg\"\\n2', '\"abcd\"\\n2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution: \n",
    "    # 当需要固定规律一段一段去处理字符串的时候，要想想在在for循环的表达式上做做文章。\n",
    "    # [::-1]用于逆转str或list\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        for i in range(0, len(s), 2*k):# 0, 2k, 4k...\n",
    "            s = s[:i] + s[i:i+k][::-1] + s[i+k:]\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s, k):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :type k: int\n",
    "        :rtype: str\n",
    "        \"\"\"\n",
    "        arr = list(s)\n",
    "        i, j = 0, k\n",
    "        while j <= len(s):\n",
    "            a, b = i, j - 1\n",
    "            while a < b:\n",
    "                arr[a], arr[b] = arr[b], arr[a]\n",
    "                a += 1\n",
    "                b -= 1\n",
    "            i = j + k\n",
    "            j = i + k\n",
    "        a, b = i, len(s) - 1\n",
    "        while a < b:\n",
    "            arr[a], arr[b] = arr[b], arr[a]\n",
    "            a += 1\n",
    "            b -= 1\n",
    "        return ''.join(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s, k):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :type k: int\n",
    "        :rtype: str\n",
    "        \"\"\"\n",
    "        n = len(s)\n",
    "        res = ''\n",
    "        if (n > 2 * k):\n",
    "            res += self.reverse(s[0:k])\n",
    "            res += s[k : 2 * k]\n",
    "            res += self.reverseStr(s[2 * k:], k)\n",
    "        elif (n >= k and n <= 2 * k):\n",
    "            res += self.reverse(s[0:k])\n",
    "            res += s[k : n]\n",
    "        else:\n",
    "            res += self.reverse(s)\n",
    "        return res\n",
    "        \n",
    "    def reverse(self, s):\n",
    "        return s[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s, k):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :type k: int\n",
    "        :rtype: str\n",
    "        \"\"\"\n",
    "        lis = list(s)\n",
    "        temp = []\n",
    "        for i in range(0,len(s),k):\n",
    "            temp.append(s[i:i+k])\n",
    "        # print(temp)\n",
    "        def func(x):\n",
    "            x, y = x[0], x[1]\n",
    "            if x % 2 == 0:\n",
    "                return ''.join(reversed(y))\n",
    "            else:\n",
    "                return y\n",
    "        temp = map(func,enumerate(temp))\n",
    "        # temp = [reversed(i) for i,v in enumerate(temp) if i % 2 == 0 else i]\n",
    "        return ''.join(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        ans=''\n",
    "        while (len(s)-len(ans))>=2*k:\n",
    "            ans+=s[len(ans):len(ans)+k][::-1]\n",
    "            ans+=s[len(ans):len(ans)+k]\n",
    "        if (len(s)-len(ans))<k:\n",
    "            ans+=s[len(ans):][::-1]\n",
    "        else:\n",
    "            ans+=s[len(ans):len(ans)+k][::-1]\n",
    "            ans+=s[len(ans):]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        s = list(s)\n",
    "        for i in range(len(s)//(2*k)+1):\n",
    "            start = 2*i*k\n",
    "            s[start:start+k] = s[start:start+k][::-1]\n",
    "        return ''.join(s)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s, k):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :type k: int\n",
    "        :rtype: str\n",
    "        \"\"\"\n",
    "        lsts=list(s)\n",
    "        i=0\n",
    "        while i <len(s)//(2*k):\n",
    "            mid = lsts[i*2*k:i*2*k+k]\n",
    "            mid.reverse()\n",
    "            lsts = lsts[:i*2*k]+mid+lsts[i*2*k+k:]\n",
    "            i+=1\n",
    "        if len(lsts)-i*2*k<k:\n",
    "            mid = lsts[i*2*k:]\n",
    "            mid.reverse()\n",
    "            lsts = lsts[:i*2*k]+mid\n",
    "        else:\n",
    "            mid = lsts[i*2*k:i*2*k+k]\n",
    "            mid.reverse()\n",
    "            lsts = lsts[:i*2*k]+mid+lsts[i*2*k+k:]\n",
    "        return ''.join(lsts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        s = list(s)\n",
    "\n",
    "        for i in range(0,len(s), 2*k):\n",
    "            s[i:i+k] = reversed(s[i:i+k])\n",
    "        return \"\".join(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        s = list(s)\n",
    "        if len(s) <k:\n",
    "            return \"\".join(s[::-1])\n",
    "        if len(s) < 2*k:\n",
    "            l = s[:k]\n",
    "            l.reverse()\n",
    "            s[:k] = l\n",
    "            return \"\".join(s)\n",
    "        index = 0 \n",
    "        end = len(s)//(2*k)*(2*k)\n",
    "        while index < end:\n",
    "            self.swap(s,index,k)\n",
    "            index += 2*k\n",
    "        if len(s)-end >=k:\n",
    "            self.swap(s,end,k)\n",
    "        elif len(s) - end <k:\n",
    "            self.swap(s,end,len(s) - end)\n",
    "        return \"\".join(s)\n",
    "\n",
    "    def swap(self,s,i,k):\n",
    "        l = s[i:i+k]\n",
    "        l.reverse()\n",
    "        s[i:i+k] = l\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        a = list(s)\n",
    "        for i in range(0, len(a), 2*k):\n",
    "            a[i:i+k] = reversed(a[i:i+k])\n",
    "        return ''.join(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\r\n",
    "\r\n",
    "class Solution:\r\n",
    "    def reverseStr(self, s: str, k: int) -> str:\r\n",
    "        if k == 1:\r\n",
    "            return s\r\n",
    "        idx = 0\r\n",
    "        s = list(s)\r\n",
    "        while idx * k < len(s):\r\n",
    "            i = idx * k\r\n",
    "            j = min(idx * k+k-1, len(s)-1)\r\n",
    "            while i < j:\r\n",
    "                s[i], s[j] = s[j], s[i]\r\n",
    "                i += 1\r\n",
    "                j -= 1\r\n",
    "            idx += 2\r\n",
    "        return ''.join(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        N = len(s)\n",
    "        re = []\n",
    "        flag = True\n",
    "        i = 0\n",
    "        while i < N:\n",
    "            t = s[i:min(i+k, N)]\n",
    "            if flag: re.append(t[::-1])\n",
    "            else: re.append(t)\n",
    "            flag = not flag\n",
    "            i += k\n",
    "        return ''.join(re)\n",
    "\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        res = []\n",
    "        while(len(s) >= 2*k):\n",
    "            res.append(s[:k][::-1]+s[k:2*k])\n",
    "            s = s[2*k:]\n",
    "        if k <= len(s) < 2*k:\n",
    "            res.append(s[:k][::-1]+s[k:])\n",
    "        if len(s) < k:\n",
    "            res.append(s[::-1])\n",
    "        return ''.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        res = ''\n",
    "\n",
    "        for i in range(0, len(s), 2*k):\n",
    "            res += s[i:i+k][::-1]\n",
    "            res += s[i+k:i+2*k]\n",
    "        return res\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        a = list(s)\n",
    "        for i in range(0, len(a), 2*k):\n",
    "            a[i:i+k] = reversed(a[i:i+k])\n",
    "        return \"\".join(a)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        l=list(s)\n",
    "        M=N=len(l)\n",
    "        i=k-1\n",
    "        while M>=k:\n",
    "            subl=l[i-k+1:i+1]\n",
    "            subl.reverse()\n",
    "            l[i-k+1:i+1]=subl\n",
    "            M=len(l[i+k+1:N])\n",
    "            i+=2*k\n",
    "        if M<k:\n",
    "            subl=l[i-k+1:N]\n",
    "            subl.reverse()\n",
    "            l[i-k+1:N]=subl\n",
    "        s=\"\"\n",
    "        for c in l:\n",
    "            s+=c\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        dic = {}\n",
    "        if(len(s)<k):\n",
    "            return s[::-1]\n",
    "        for i in range(len(s)):\n",
    "            if((i//k)%2 == 0):\n",
    "                if(i//k == 0):\n",
    "                    dic[i] = s[k-1-i]\n",
    "                elif(i>=(len(s)//k)*k):\n",
    "                    dic[i] = s[(len(s) - (len(s)//k)*k-1-i)+(len(s)//k*k)*2]\n",
    "                else:\n",
    "                    x = i//k\n",
    "                    y = k-1-(i-x*k)+x*k\n",
    "                    dic[i] = s[y]\n",
    "            else:\n",
    "                dic[i] = s[i]\n",
    "        return ''.join(dic.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        i = 0\n",
    "        res = \"\"\n",
    "\n",
    "        def reverse_s(ss):\n",
    "            if len(ss) < 1:\n",
    "                return ss\n",
    "            else:\n",
    "                return reverse_s(ss[1:]) + ss[0]\n",
    "\n",
    "        while i < len(s):\n",
    "            j = min(i + 2 * k, len(s))\n",
    "            s_tmp = s[i: j]\n",
    "            if len(s_tmp) == 2 * k:\n",
    "                res += reverse_s(s_tmp[:k]) + s_tmp[k:]\n",
    "            elif len(s_tmp) >= k and len(s_tmp) < 2 * k:\n",
    "                res += reverse_s(s_tmp[:k]) + s_tmp[k:]\n",
    "            else:\n",
    "                res += reverse_s(s_tmp)\n",
    "            i = i + 2 * k\n",
    "        \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        '''t=list(s)\n",
    "        n=0\n",
    "        while n<len(s)//(2*k):\n",
    "            a=t[2*n*k:(2*n+1)*k]\n",
    "            a.reverse()\n",
    "            print(a)\n",
    "            i=0\n",
    "            while i<k:\n",
    "                t.pop(2*n*k)\n",
    "                i+=1\n",
    "            print(t)\n",
    "            j=0\n",
    "            while j<k:\n",
    "                t.insert(2*n*k,a[j])\n",
    "            #t.insert(2*n*k,a)#这里再想办法将t的如上这一切片替换为切片a\n",
    "            print(t)\n",
    "            n=n+1\n",
    "        #再处理尾部\n",
    "        return t'''\n",
    "\n",
    "\n",
    "        n=0\n",
    "        n_max=len(s)//(2*k)\n",
    "        while n<n_max:\n",
    "            a=s[2*n*k:(2*n+1)*k]\n",
    "            print(a)\n",
    "            b=a[::-1]\n",
    "            print(b)\n",
    "            s=s.replace(s[2*n*k:(2*n+1)*k],b)\n",
    "            print(s)\n",
    "            n=n+1\n",
    "        remain=s[n_max*2*k:(n_max*2*k+k)]\n",
    "        remain_reverse=remain[::-1]\n",
    "        s=s.replace(s[n_max*2*k:(n_max*2*k+k)],remain_reverse)\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        res = ''\n",
    "        flag = True\n",
    "        for i in range(0, len(s), k):\n",
    "          res += s[i:i+k][::-1] if flag else s[i:i+k]\n",
    "          flag = not flag\n",
    "        return res   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        t = list(s)\n",
    "        for i in range(0, len(t), 2 * k):\n",
    "            t[i: i + k] = reversed(t[i: i + k])\n",
    "        return \"\".join(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        p = 0\n",
    "        while p < len(s):\n",
    "            p2 = p + k\n",
    "            s = s[:p] + s[p:p2][::-1] + s[p2:]\n",
    "            p = p + 2 * k\n",
    "        return s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        l=len(s)\n",
    "        n=l//k\n",
    "        s=list(s)\n",
    "        for i in range(n):\n",
    "            if i%2==0:\n",
    "                left=i*k\n",
    "                right=(i+1)*k-1\n",
    "                while left<right:\n",
    "                    s[left],s[right]=s[right],s[left]\n",
    "                    left+=1\n",
    "                    right-=1\n",
    "        if n%2==0 and l-n*k != 0:\n",
    "            left=n*k\n",
    "            right=l-1\n",
    "            while left<right:\n",
    "                s[left],s[right]=s[right],s[left]\n",
    "                left+=1\n",
    "                right-=1\n",
    "        res=str()\n",
    "        for i in s:\n",
    "            res+=''.join(i)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "\n",
    "        def reverse(s):\n",
    "            count = len(s) // 2 \n",
    "\n",
    "\n",
    "            left, right = 0, len(s) - 1\n",
    "\n",
    "            while count > 0:\n",
    "                s[left], s[right] = s[right], s[left]\n",
    "                count -= 1\n",
    "                left += 1 \n",
    "                right -= 1\n",
    "            return s\n",
    "\n",
    "\n",
    "        s = list(s)\n",
    "        i = 0 \n",
    "        if k >= len(s):\n",
    "            s = reverse(s)\n",
    "        else:\n",
    "            while i + k < len(s):\n",
    "                s = s[0: i] + reverse(s[i: i + k]) + s[i + k :]\n",
    "                i += 2 * k\n",
    "                if len(s) - 1 - i < k :\n",
    "                    s = s[0:i] + reverse(s[i:]) \n",
    "                    break \n",
    "                if len(s) - 1 - 1 < 2 * k and len(s) - 1 - 1 >= k:\n",
    "                    s = s[0:i] + reverse(s[i:k]) + s[k:]\n",
    "                    break\n",
    "\n",
    "        return ''.join(s)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        chars = list(s)\n",
    "        l = len(chars)\n",
    "        i = 0\n",
    "        while i < l:\n",
    "            end = min(i + k, l)\n",
    "            self.reverseString(chars, i, end)\n",
    "            i += 2 * k\n",
    "        return ''.join(chars)\n",
    "\n",
    "    def reverseString(self, s: List[str], start: int, end: int) -> None:\n",
    "        while start < end:\n",
    "            s[start], s[end - 1] = s[end - 1], s[start]\n",
    "            start += 1\n",
    "            end -= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        res=list(s)\n",
    "        for i in range(0,len(res),2*k):\n",
    "            res[i:i+k]=res[i:i+k][::-1]\n",
    "        return \"\".join(res)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def reverseStr(self, s: str, k: int) -> str:\n",
    "        p = 0\n",
    "        while p < len(s):\n",
    "            s = s[:p]+s[p:p+k][::-1]+s[p+k:]\n",
    "            p += 2*k\n",
    "        return s"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
